# /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 11:18
# @Author  : lt
# @Email   : lt@163.com
# @File    : xiansuo_xiangqing_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from page.KHGL_page.Base_Page import BasePage
from time import sleep
class XianSuo_XiangQing(BasePage):

    # 定位添加文件按钮
    add_file = (By.CSS_SELECTOR, '#right_list > ul > li:nth-child(5) > a')
    # 定位文件输入框
    add_button_locator = (By.XPATH, '//*[@id="attachment1"]/input')
    # 定位添加按钮
    add_locator = (By.XPATH, '//*[@id="dialog-file"]/form/table/tbody/tr[3]/td[2]/input[1]')
    # 定位添加成功
    succceful_locator = (By.XPATH, '//*[@id="tab1"]/div[2]/div')
    # 定位文件按钮
    file_locator = (By.CSS_SELECTOR, '#left_list > li:nth-child(7) > a')
    # 定位所有文件这张表
    delete_locator = (By.CSS_SELECTOR, '#tab3 > table > tbody')

    # 点击添加文件
    def wenjian_button(self):
        self.driver.find_element(*self.add_file).click()
    # 上传文件
    def wenjian_neirong(self,wenjian):
        self.driver.find_element(*self.add_button_locator).send_keys(wenjian)
    # 点击添加按钮
    def tianjia_button(self):
        self.driver.find_element(*self.add_locator).click()
    # 判断是否添加成功
    def tianjia_succedul(self):
     text = self.driver.find_element(*self.succceful_locator).text
     return text
    # 点击文件按钮
    def wenjian_anniu(self):
        self.driver.find_element(*self.file_locator).click()
    #找到文件并删除
    def delete_wenjian(self,wenjian_name):
        tobdys = self.driver.find_element(*self.delete_locator)
        trs1 = tobdys.find_elements(By.TAG_NAME, 'tr')[1:]
        sleep(5)
        for e in trs1:
            tds1 = e.find_elements(By.TAG_NAME, 'td')
            if tds1[1].text == wenjian_name:
                # 定位并删除添加的文件
                tds1[0].find_element(By.CSS_SELECTOR, '.del_confirm').click()
                sleep(4)
                self.driver.switch_to.alert.accept()
                break